package com.cloud.prac.endecrypt;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;

@Slf4j
public class Test {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String str = "a";
        char[] arr = str.toCharArray();
        for (char c : arr) {
            // 对应 ascii 码
            log.info("{}", c);
        }
        byte[] bytes = str.getBytes();
        for (byte b : bytes) {
            // byte 对应的 bit
            String s = Integer.toBinaryString(b);
            log.info("{}", s);
        }

        // utf-8 字符集下中文占3个字符;GBk下占2个字符
        String str2 = "好";
        byte[] bytes1 = str2.getBytes("GBK");
        for (byte b : bytes1) {
            log.info("{}", b);
            String s = Integer.toBinaryString(b);
            log.info("{}", s);
        }

    }

}
